﻿@using ZBJF.Warranty.BLL
@using ZBJF.Warranty.Common.Enums.Base
@using ZBJF.Warranty.Common.Enums.InfoCollect
@using ZBJF.Warranty.Common.Enums.InsuranceProducts
@using ZBJF.Warranty.Common.Enums.InsuranceWarranty
@using EnumHelper = ZBJF.Warranty.Common.Common.EnumHelper
@model ZBJF.Warranty.Model.InsuranceWarrantyRecord
@{
    var auditProjectType = (byte)PageData["AuditProjectType"];
    var type = PageData["Type"];//是否是显示审核结果ShowResult

    var cellPhoneInsuranceInfo = ServiceFactory.CellPhoneInsuranceInfoServiceInstance.Load(
        Model.InsuranceOrderServiceProjectId ?? 0);
    var cellPhoneServiceProjectID = cellPhoneInsuranceInfo != null && cellPhoneInsuranceInfo.CellPhoneServiceProjectID.HasValue
        ? cellPhoneInsuranceInfo.CellPhoneServiceProjectID.Value
        : 0;
    var serviceProjectType = (ServiceProductType)(Model.ServiceProjectType ?? 0);
    var auditProjectConfigurationList = ServiceFactory.InsuranceProductAuditProjectConfigurationSnapshootServiceInstance.GetAuditProjectConfigurationList(Model.InsuranceOrderServiceProjectId ?? 0, serviceProjectType, auditProjectType).ToList();
    if (!auditProjectConfigurationList.Any())
    {
        auditProjectConfigurationList = ServiceFactory.InsuranceProductsAuditProjectConfigurationMappingsServiceInstance.GetAuditProjectConfigurationList(new List<int>(cellPhoneServiceProjectID), serviceProjectType, auditProjectType).ToList();
    }
    if (auditProjectType <= 0) //维修前检测
    {
        auditProjectConfigurationList = auditProjectConfigurationList.Where(o => o.AuditProjectWithType != (byte)AuditProjectType.MaintenanceCompletionTest && o.AuditProjectWithType != (byte)AuditProjectType.RepairCenter).ToList();
    }
}
<h4>
    @if (auditProjectType > 0)
    {
        @EnumHelper.Instance.GetDescription(typeof(AuditProjectType), auditProjectType)
    }
    else
    {
        <text>维修前检测结果</text>
    }
</h4>
@if (type == "ShowResult")
{
    <input type="hidden" name="insuranceWarrantyRecordID" value="@Model.ID" />
    <table class="table table-responsive table-bordered table-hover">
        <tr>
            @if (auditProjectType <= 0)
            {
                <th>审核阶段</th>
            }
            <th>审核项目</th>
            <th>审核结果</th>
            <th>审核备注</th>
            <th>审核人</th>
            <th>审核时间</th>
        </tr>
        @{
            var auditResultProjectID = -1;
            var auditResultHtml = "";
        }
        @for (int i = 0; i < auditProjectConfigurationList.Count; i++)
        {
            var auditProjectConfiguration = auditProjectConfigurationList[i];
            var result = ServiceFactory.InsuranceWarrantyRecordAuditInfoServiceInstance.Load(Model.ID, auditProjectConfiguration.AuditProjectWithType, auditProjectConfiguration.AuditProjectID);
            var filedType = auditProjectConfiguration.FieldType;
            if (auditResultProjectID != auditProjectConfiguration.AuditProjectID)
            {
                <tr>
                    @if (auditProjectType <= 0)
                    {
                        <td>
                            @EnumHelper.Instance.GetDescription(typeof(AuditProjectType), auditProjectConfiguration.AuditProjectWithType)

                        </td>
                    }
                    <td>
                        @auditProjectConfiguration.AuditProjectName
                    </td>
                    <td id="tdDisabled_@auditProjectConfiguration.AuditProjectID">
                        @if (!string.IsNullOrEmpty(auditResultHtml))
                        {
                            <script type="text/javascript">
                                $("#tdDisabled_@auditResultProjectID").html("@Html.Raw(auditResultHtml)");
                            </script>
                            auditResultHtml = "";
                        }
                        @if (filedType == (byte)FieldTypeEnum.Text)
                        {
                            auditResultHtml += "<input type='text' disabled  value='" + (result != null ? result.AuditResult : "") + "' />";
                        }
                        else if (filedType == (byte)FieldTypeEnum.CheckBoxList)
                        {
                            auditResultHtml += "<label><input type='checkbox' disabled " + (result != null ? (result.AuditResult.Contains(auditProjectConfiguration.OptionID.ToString()) ? "checked" : "") : "") + " value='" + auditProjectConfiguration.OptionID + "'/>" + auditProjectConfiguration.OptionName + "</label>";
                        }
                        else if (filedType == (byte)FieldTypeEnum.DropDownList)
                        {
                            auditResultHtml += "<label><input type='radio' disabled " + (result != null ? (result.AuditResult.Contains(auditProjectConfiguration.OptionID.ToString()) ? "checked" : "") : "") + " value='" + auditProjectConfiguration.OptionID + "'/>" + auditProjectConfiguration.OptionName + "</label>";
                        }
                    </td>
                    <td>
                        @if (result != null)
                        {
                            @result.AuditRemark
                        }
                    </td>
                    <td>
                        @if (result != null)
                        {
                            @result.CreatedBy
                        }
                    </td>
                    <td>
                        @if (result != null)
                        {
                            @result.CreatedTime
                        }
                    </td>
                </tr>
                        auditResultProjectID = auditProjectConfiguration.AuditProjectID;
            }
            else
            {
                if (filedType == (byte)FieldTypeEnum.CheckBoxList)
                {
                    auditResultHtml += "<label><input type='checkbox' disabled  " + (result != null ? (result.AuditResult.Contains(auditProjectConfiguration.OptionID.ToString()) ? "checked" : "") : "") + " value='" + auditProjectConfiguration.OptionID + "'/>" + auditProjectConfiguration.OptionName + "</label>";
                }
                else if (filedType == (byte)FieldTypeEnum.DropDownList)
                {
                    auditResultHtml += "<label><input type='radio' disabled  " + (result != null ? (result.AuditResult.Contains(auditProjectConfiguration.OptionID.ToString()) ? "checked" : "") : "") + " value='" + auditProjectConfiguration.OptionID + "'/>" + auditProjectConfiguration.OptionName + "</label>";
                }
            }
            if (i == auditProjectConfigurationList.Count - 1)
            {
                <script type="text/javascript">
                    $("#tdDisabled_@auditResultProjectID").html("@Html.Raw(auditResultHtml)");
                </script>
            }
        }
    </table>
}
else
{
    <form id="auditInfoForm" enctype="multipart/form-data" method="post">
        <input type="hidden" name="InsuranceWarrantyRecordID" id="InsuranceWarrantyRecordID" value="@Model.ID" />
        <table class="table table-responsive table-bordered table-hover">
            <tr>
                <th>审核项目</th>
                <th>审核结果</th>
                <th>审核备注</th>
            </tr>
            @{
    var auditProjectID = -1;
    var html = "";
    var index = -1;
            }
            @for (int i = 0; i < auditProjectConfigurationList.Count; i++)
            {
                var auditProjectConfiguration = auditProjectConfigurationList[i];
                var result = ServiceFactory.InsuranceWarrantyRecordAuditInfoServiceInstance.Load(Model.ID, auditProjectType, auditProjectConfiguration.AuditProjectID);
                var filedType = auditProjectConfiguration.FieldType;
                if (auditProjectID != auditProjectConfiguration.AuditProjectID)
                {
                    index++;
                    <tr>
                        <td>
                            <input type="hidden" name="InsuranceWarrantyRecordAuditInfo[@index].ID" value="@(result != null ? result.ID : 0)" />
                            <input type="hidden" name="InsuranceWarrantyRecordAuditInfo[@index].AuditWith" value="@(auditProjectType)" />
                            <input type="hidden" name="InsuranceWarrantyRecordAuditInfo[@index].AuditProjectConfigurationID" value="@auditProjectConfiguration.AuditProjectID" />
                            @auditProjectConfiguration.AuditProjectName
                        </td>
                        <td id="td_@(auditProjectType)_@auditProjectConfiguration.AuditProjectID">
                            @if (!string.IsNullOrEmpty(html))
                            {
                                <script type="text/javascript">
                                    $("#td_@(auditProjectType)_@auditProjectID").html("@Html.Raw(html)");
                                </script>
                                html = "";
                            }
                            @if (filedType == (byte)FieldTypeEnum.Text)
                            {
                                html += "<input type='text' validate={required:true,messages:{required:'请选择审核结果'}}  name='InsuranceWarrantyRecordAuditInfo[" + index + "].AuditResult' value='" + (result != null ? result.AuditResult : "") + "' />";
                            }
                            else if (filedType == (byte)FieldTypeEnum.CheckBoxList)
                            {
                                html += "<label><input type='checkbox' validate={required:true,messages:{required:'请选择审核结果'}}  name='InsuranceWarrantyRecordAuditInfo[" + index + "].AuditResult' " + (result != null ? (result.AuditResult.Contains(auditProjectConfiguration.OptionID.ToString()) ? "checked" : "") : "") + " value='" + auditProjectConfiguration.OptionID + "'/>" + auditProjectConfiguration.OptionName + "</label>";
                            }
                            else if (filedType == (byte)FieldTypeEnum.DropDownList)
                            {
                                html += "<label><input type='radio' validate={required:true,messages:{required:'请选择审核结果'}}  name='InsuranceWarrantyRecordAuditInfo[" + index + "].AuditResult' " + (result != null ? (result.AuditResult.Contains(auditProjectConfiguration.OptionID.ToString()) ? "checked" : "") : "") + " value='" + auditProjectConfiguration.OptionID + "'/>" + auditProjectConfiguration.OptionName + "</label>";
                            }
                        </td>
                        <td>
                            @if (result != null)
                            {
                                <input type="text" name="InsuranceWarrantyRecordAuditInfo[@index].AuditRemark" value="@result.AuditRemark" class="w-p75" />
                            }
                            else
                            {
                                <input type="text" name="InsuranceWarrantyRecordAuditInfo[@index].AuditRemark" class="w-p75" />
                            }
                        </td>
                    </tr>
                            auditProjectID = auditProjectConfiguration.AuditProjectID;
                }
                else
                {
                    if (filedType == (byte)FieldTypeEnum.CheckBoxList)
                    {
                        html += "<label><input type='checkbox'  name='InsuranceWarrantyRecordAuditInfo[" + index + "].AuditResult'  " + (result != null ? (result.AuditResult.Contains(auditProjectConfiguration.OptionID.ToString()) ? "checked" : "") : "") + " value='" + auditProjectConfiguration.OptionID + "'/>" + auditProjectConfiguration.OptionName + "</label>";
                    }
                    else if (filedType == (byte)FieldTypeEnum.DropDownList)
                    {
                        html += "<label><input type='radio'  name='InsuranceWarrantyRecordAuditInfo[" + index + "].AuditResult'  " + (result != null ? (result.AuditResult.Contains(auditProjectConfiguration.OptionID.ToString()) ? "checked" : "") : "") + " value='" + auditProjectConfiguration.OptionID + "'/>" + auditProjectConfiguration.OptionName + "</label>";
                    }
                }
                if (i == auditProjectConfigurationList.Count - 1)
                {
                    <script type="text/javascript">
                        $("#td_@(auditProjectType)_@auditProjectID").html("@Html.Raw(html)");
                    </script>
                }
            }
        </table>
    </form>
}
